package calculator;

import java.util.List;



public class Expression {

	private List<String> expression;

	public Expression(List<String> exp) {
		this.expression = exp;
	}

	public int getNumber(int i) {		
		return Integer.parseInt(expression.get(i));
	}

	public void replace(int index, int newValue) {
		expression.remove(index - 1);
		expression.remove(index - 1);
		expression.remove(index - 1);
		expression.add(index - 1, String.valueOf(newValue));
	}

	public String getOperator(int i) {
		
		String operator = expression.get(i);
		if (!("+".equals(operator) || "-".equals(operator) || "*".equals(operator)
				|| "/".equals(operator)))	{
			throw new IllegalArgumentException("El operador "
					+ operator + " no pertenece al conjunto de operadores permitidos");
		}
		return operator;
	}

	public BinaryOperation getBinaryOperation(int i) {
		
		return new BinaryOperation(getOperator(i), getNumber(i - 1), getNumber(i + 1) )	
		;
	}

}
